﻿using System;
using System.ComponentModel;

namespace YArchitech.Controls
{
	public class HYPropertyDescriptor : PropertyDescriptor
	{
		public HYPropertyDescriptor(HYProperty prop, Attribute[] attrs) : base(prop.Name, attrs)
		{
			this.theProp = prop;
		}

		public override bool CanResetValue(object component)
		{
			return false;
		}

		public override Type ComponentType
		{
			get
			{
				return base.GetType();
			}
		}

		public override string Name
		{
			get
			{
				return this.theProp.Name;
			}
		}

		public override object GetValue(object component)
		{
			return this.theProp.Value;
		}

		public override string Category
		{
			get
			{
				return this.theProp.Category;
			}
		}

		public override string Description
		{
			get
			{
				return this.theProp.Description;
			}
		}

		public override bool IsReadOnly
		{
			get
			{
				return this.theProp.ReadOnly;
			}
		}

		public override Type PropertyType
		{
			get
			{
				return this.theProp.Value.GetType();
			}
		}

		public override void ResetValue(object component)
		{
		}

		public override void SetValue(object component, object value)
		{
			this.theProp.Value = value;
		}

		public override bool ShouldSerializeValue(object component)
		{
			return false;
		}

		public override string DisplayName
		{
			get
			{
				if (!(this.theProp.DisplayName != ""))
				{
					return this.theProp.Name;
				}
				return this.theProp.DisplayName;
			}
		}

		public override TypeConverter Converter
		{
			get
			{
				return this.theProp.Converter;
			}
		}

		public override object GetEditor(Type editorBaseType)
		{
			if (this.theProp.Editor != null)
			{
				return this.theProp.Editor;
			}
			return base.GetEditor(editorBaseType);
		}

		private HYProperty theProp;
	}
}
